package cc.eddic.pratice.programmingparadigms;

import cc.eddic.pratice.programmingparadigms.emp01array.EmployeeReaderService;
import cc.eddic.pratice.programmingparadigms.emp01array.EmployeeStatisticsService;
import cc.eddic.pratice.programmingparadigms.emp01array.impl.*;

import cc.eddic.pratice.programmingparadigms.emp01array.impl.ReaderGcsImpl;
import cc.eddic.pratice.programmingparadigms.emp01array.impl.StatisticsGcsImpl;
import cc.eddic.pratice.programmingparadigms.emp01array.impl.StatisticsZyzImpl;
import cc.eddic.pratice.programmingparadigms.emp01array.impl.StatisticsGcsInnerClassImpl;

import cc.eddic.pratice.programmingparadigms.emp01array.impl.StatisticsWqjImpl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


@Slf4j
@Controller
@RequestMapping("/employee-array")
public class EmployeeController {


    // 曾奕哲实现的版本
    @RequestMapping("/stat-zyz")
    public String statZyz(Model model) {
        EmployeeReaderService readerService = new ExcelReaderZyzImpl();
        EmployeeStatisticsService statisticsService = new StatisticsZyzImpl();
        addAttributes(model, readerService, statisticsService);
        return THYMELEAF_STAT;
    }


    // 李惠实现的版本
    @RequestMapping("/stat-lh")
    public String statlh(Model model) {

        EmployeeReaderService readerService = new StatisticsGcsImpl();

        EmployeeStatisticsService statisticsService = new StatisticsLhImpl();
        addAttributes(model, readerService, statisticsService);
        return THYMELEAF_STAT;
    }
    // 孙晨玮实现的版本
    @RequestMapping("/stat-scw")
    public String statScw(Model model) {
        EmployeeReaderService readerService = new StatisticsGcsImpl();
        EmployeeStatisticsService statisticsService = new StatisticsZyzImpl();
        addAttributes(model, readerService, statisticsService);
        return THYMELEAF_STAT;
    }

    // 王巧家实现的版本
    @RequestMapping("/stat-wqj")
    public String statWqj(Model model) {
        EmployeeReaderService readerService = new StatisticsGcsImpl();
        EmployeeStatisticsService statisticsService = new StatisticsWqjImpl();

        addAttributes(model, readerService, statisticsService);
        return THYMELEAF_STAT;
    }

    // 崔相元实现的版本
    @RequestMapping("/stat-cxy")
    public String statCxy(Model model) {
        EmployeeReaderService readerService = new StatisticsGcsImpl();
        EmployeeStatisticsService statisticsService = new StatisticsCxyImpl();
        addAttributes(model, readerService, statisticsService);
        return THYMELEAF_STAT;
    }



    // 谷常生实现的版本
    @RequestMapping("/stat-gucs")
    public String statGcs(Model model) {
        EmployeeReaderService readerService = new ReaderGcsImpl();
        EmployeeStatisticsService statisticsService = new StatisticsGcsInnerClassImpl();
        addAttributes(model, readerService, statisticsService);
        return THYMELEAF_STAT;
    }
//    lx
    public static void lx(){
        System.out.print("xxxxxxx");
    }

    // 谷常生实现的版本
    @RequestMapping("/stat-lx")
    public String statLx(Model model) {
        EmployeeReaderService readerService = new ReaderGcsImpl();
        EmployeeStatisticsService statisticsService = new StatisticsLxImpl();
        addAttributes(model, readerService, statisticsService);
        return THYMELEAF_STAT;
    }
    // 谭雨晴实现的版本
    @RequestMapping("/stat-tyq")
    public String statTyq(Model model) {
        EmployeeReaderService readerService = new ReaderGcsImpl();
        EmployeeStatisticsService statisticsService = new StatisticsTyqImpl();
        addAttributes(model, readerService, statisticsService);
        return THYMELEAF_STAT;
    }


    private static void addAttributes(Model model, EmployeeReaderService readerService, EmployeeStatisticsService statisticsService) {
        Employee[] employees = readerService.read("C:\\Users\\zyz\\Desktop\\personal_information_20230718105609.xlsx");
        model.addAttribute("employees", employees);
        model.addAttribute("byGender", statisticsService.pivotByGender(employees));
        model.addAttribute("byDepartment", statisticsService.pivotByDepartment(employees));
        model.addAttribute("byJobTitle", statisticsService.pivotByJobTitle(employees));
    }

    private final String THYMELEAF_STAT = "employee-statistics";
}
